package com.vizhuo.push.umeng.android;

import org.apache.commons.lang.StringUtils;

import com.vizhuo.push.umeng.base.PushConstant;
import com.vizhuo.push.umeng.base.PushFilter;

/**
 * @author YuanWenLong 作者 E-mail: yuanwenlong2010@163.com
 * @date 创建时间：2015年6月19日 上午10:17:50
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class AndroidSendRequest {
    private String appkey;

    private String timestamp = Integer.toString((int) (System.currentTimeMillis() / 1000));

    private String type;

    /**
     * 设备唯一表示 当type=unicast时,必填, 表示指定的单个设备 当type=listcast时,必填,要求不超过500个,
     * 多个device_token以英文逗号间隔
     */
    private String device_tokens;

    private String alias_type;

    private String alias;

    private String file_id;

    private PushFilter filter;

    private AndroidPayload payload;

    private AndroidPolicy policy;

    private String production_mode;

    private String description;

    private String thirdparty_id;

    public String checkParameter() {
        if (StringUtils.isEmpty(appkey)) {
            return "appkey必填";
        } else if (StringUtils.isEmpty(timestamp)) {
            return "timestamp必填";
        } else if (StringUtils.isEmpty(type)) {
            return "type必填";
        } else if (payload == null) {
            return "payload必填";
        } else if (StringUtils.isEmpty(payload.getDisplay_type())) {
            return "display_type必填";
        } else if (payload.getBody() == null) {
            return "body必填";
        } else if (StringUtils.isEmpty(payload.getBody().getAfter_open())) {
            return "after_open必填";
        }
        if (PushConstant.TYPE_UNICAST.equals(type)) {
            if (StringUtils.isEmpty(device_tokens)) {
                return "单播device_tokens必填";
            }
        } else if (PushConstant.TYPE_LISTCAST.equals(type)) {
            if (StringUtils.isEmpty(device_tokens)) {
                return "列播device_tokens必填";
            }
            if (device_tokens.split(",").length > 500) {
                return "列播device_tokens不得超过500个";
            }
        } else if (PushConstant.TYPE_FILECAST.equals(type)) {
            if (StringUtils.isEmpty(file_id)) {
                return "文件播file_id不得为空";
            }
        }

        if (payload.getDisplay_type().equals(PushConstant.DISPLAY_TYPE_NOTIFICATION)) {
            if (StringUtils.isEmpty(payload.getBody().getText())) {
                return "text必填";
            } else if (StringUtils.isEmpty(payload.getBody().getTitle())) {
                return "title必填";
            } else if (StringUtils.isEmpty(payload.getBody().getTicker())) {
                return "ticker必填";
            }

        }
        return null;

    }

    public String getAppkey() {
        return appkey;
    }

    public void setAppkey(String appkey) {
        this.appkey = appkey;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDevice_tokens() {
        return device_tokens;
    }

    public void setDevice_tokens(String device_tokens) {
        this.device_tokens = device_tokens;
    }

    public String getAlias_type() {
        return alias_type;
    }

    public void setAlias_type(String alias_type) {
        this.alias_type = alias_type;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getFile_id() {
        return file_id;
    }

    public void setFile_id(String file_id) {
        this.file_id = file_id;
    }

    public PushFilter getFilter() {
        return filter;
    }

    public void setFilter(PushFilter filter) {
        this.filter = filter;
    }

    public AndroidPayload getPayload() {
        return payload;
    }

    public void setPayload(AndroidPayload payload) {
        this.payload = payload;
    }

    public AndroidPolicy getPolicy() {
        return policy;
    }

    public void setPolicy(AndroidPolicy policy) {
        this.policy = policy;
    }

    public String getProduction_mode() {
        return production_mode;
    }

    public void setProduction_mode(String production_mode) {
        this.production_mode = production_mode;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getThirdparty_id() {
        return thirdparty_id;
    }

    public void setThirdparty_id(String thirdparty_id) {
        this.thirdparty_id = thirdparty_id;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

}
